﻿/// <reference path="common.js" />
/// <reference path="zepto.min.js" />

/*
window.onbeforeunload = function () {
    jc.cookie.add("back_url", window.location.href);
}

*/

window.checkDevice = function () {
    if (window.location.hostname != "localhost" && window.location.hostname != "172.21.17.136") {
        if (window.location.toString().indexOf('pref=padindex') != -1) {
        } else {
            if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
                if (window.location.href.indexOf("?mobile") < 0) {
                    try {
                        if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {

                        } else if (/iPad/i.test(navigator.userAgent)) {
                            window.location.replace(jc.cookie.get("sitePcUrl"));
                        } else {

                        }
                    } catch (e) { }
                }
            }
            else {
                window.location.replace(jc.cookie.get("sitePcUrl"));
            }
        }
    }
}

/* 判断是否微信 */
window.isWeixn = function () {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

//window.serverPath = "http://localhost:8080/cc/api";

window.serverPath = "http://shipin.zy.com/api";

//window.serverPath = "http://test.yuyou100.com/cc-web/api";

window.ctx = "";
if (window.location.hostname == "localhost") {
    window.ctx = window.location.origin + "/";
}
else if (window.location.hostname == "test.yuyou100.com") {
    window.ctx = window.location.origin + "/cc-h5/";
}
else if(window.location.hostname == "shipin.zy.com") {
    window.ctx = window.location.origin + "/h5/";
}else {
    window.ctx = window.location.origin + "/cc-h5/";
}

window.qiniuCDN = 'http://7xwcmb.com1.z0.glb.clouddn.com/';


window.path = {
    /* 网站信息 */
    siteConfig: window.serverPath + "/site/config",

    /* 正在直播课程 */
    livingCourse: window.serverPath + "/livingCourse",

    /* 最新课程 */
    newCourse: window.serverPath + "/newCourse",

    /* 推荐课程 */
    hotCourse: window.serverPath + "/hotCourse",

    /* 课程信息 */
    courseDetail: window.serverPath + "/courseDetail",

    /* 课程更多信息 */
    courseMoreInfo: window.serverPath + "/course/moreInfo",

    /* banner */
    banner: window.serverPath + "/banner",

    /* 登录 */
    login: window.serverPath + "/login",

    /* 课程列表 */
    queryCourse: window.serverPath + "/queryCourse",

    /* 课程列表筛选条件 */
    gradeAndSubject: window.serverPath + "/base/gradeAndSubject",

    /* 购物车列表 */
    shoppingCart: window.serverPath + "/member/shoppingCart",

    /* 计算优惠 */
    calDiscount: window.serverPath + "/member/calDiscount",

    /* 获取购物车次数 */
    cartCount: window.serverPath + "/member/shoppingCart/count",

    /* 添加购物车 */
    cartAdd: window.serverPath + "/member/shoppingCart/add",

    /* 删除购物车 */
    cartDelect: window.serverPath + "/member/shoppingCart/del",

    /* 我的订单 */
    order: window.serverPath + "/member/order",

    /* 获取订单 */
    getOrder: window.serverPath + "/member/getOrder",

    /* 创建订单 */
    createOrder: window.serverPath + "/member/createOrder",

    /* 删除订单 */
    closeOrder: window.serverPath + "/member/closeOrder",

    /* 支付订单 */
    payOrder: window.serverPath + "/member/payOrder",

    /* 用户信息 */
    profile: window.serverPath + "/member/profile",

    /* 更新用户信息*/
    profileUpdate: window.serverPath + "/member/profile/update",

    /* 我的课程 */
    myCourse: window.serverPath + "/member/myCourse",

    /* 用户注册 发送验证码 */
    sendCode: window.serverPath + "/sms/sendCode",

    /* 用户注册 验证验证码 */
    validCode: window.serverPath + "/sms/validCode",

    /* 用户注册 */
    register: window.serverPath + "/register",

    /* 重置密码 */
    resetPassword: window.serverPath + "/resetPassword",

    /* 获取随机试听ID */
    playerRandomId: window.serverPath + "/random/id",

    /* 拿直播地址 lectureId */
    liveUrl: window.serverPath + "/view/live/url",

    /* 监听视频推流状态 */
    liveStatus: window.serverPath + "/view/live/stream/status",

    /* 拿点播地址  */
    videoUrl: window.serverPath + "/view/video/url",

    /* 获取讲信息 */
    lecture: window.serverPath + "/lecture",

    /* 查询是否有试听时间 */
    viewCheck: window.serverPath + "/view/check",

    /* 课程基本信息 */
    course: window.serverPath + "/course",

    /* 直播群组信息 */
    groupInfo: window.serverPath + "/group/info",

    /* 直播统计 */
    viewLiving: window.serverPath.replace("api", "stat") + "/viewLiving",

    /* 点播统计 */
    viewVideo: window.serverPath.replace("api", "stat") + "/viewVideo",

    /* 获取验证码 */
    captcha: window.serverPath.replace("/api", "") + "/captcha",

    /* 查询是否需要验证码 */
    checkNeedCaptcha: window.serverPath + "/login/checkNeedCaptcha",

    /* 手机是否注册 */
    verifyPhoneNo: window.serverPath + "/verifyPhoneNo",

    /* 上传头像 */
    uploadToken: window.serverPath + '/qiniu/upload/token'


};

/* 获取网站信息 */
$.ajax({
    type: "GET",
    url: window.path.siteConfig,
    data: {},
    async: false,
    success: function (result) {
        if (result.success) {
            var data = result.data;
            jc.cookie.add("logoUrl", data.logoUrl);
            jc.cookie.add("siteKeyword", data.siteKeyword);
            jc.cookie.add("siteTitle", data.siteTitle);
            jc.cookie.add("sitePcUrl", data.sitePcUrl);
        }
        $(document.body).append(data.siteStatCode);
    },
    error: function () {
        alert("网站信息获取失败,点击确定自动刷新页面");
        window.location.reload();
    },
    dataType: "json"
});

/* 客户端检测 */
//window.checkDevice();

/* 获取匿名用户 */
if (!jc.cookie.get("u")) {
    $.getJSON(window.path.playerRandomId, {}, function (result) {
        var data = result.data;
        if (data) {
            jc.cookie.add("u", data);
        }
    });
}


window.errorRouter = function (desc) {
    if (desc === "login") {
        window.location.href = window.ctx + "login/login.html#callbackUrl=" + encodeURIComponent(window.location.href);
    }
    else if (desc == "token不能为空" || desc == "accessToken不存在" || desc == "accessToken已过期") {
        alert("页面已过期，请重新登录");
        window.location.href = window.ctx + "login/login.html#callbackUrl=" + encodeURIComponent(window.location.href);
    }
    else {
        alert(desc);
    }

}

window.nav = {
    current: 0,
    data: [
    ]
};
